package com.applet.api.interceptor;

import com.applet.code.util.AccessTokenManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {

//    @Autowired
//    private AccessTokenManager tokenManager;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        boolean flag = true;
//        String userId = request.getHeader(Constant.api_header_userId);
//        String accessToken = request.getHeader(Constant.api_header_accessToken);
//       // String lang = request.getHeader(Constant.api_header_lang);
//        if (userId != null && !"".equals(userId) && accessToken != null && !"".equals(accessToken)) {
//            Integer source = DeviceUtil.getPlatform(request);
//            flag = tokenManager.check(Integer.parseInt(userId), accessToken, source);
//        }
//        if (!flag) {
//            String msg = "会话超时";
//            ResultResponse result = new ResultResponse();
//            result.setCode("-1");
//            result.setSuccess(false);
//            result.setMsg(msg);
//            String responseConetnt = JSONObject.toJSONString(result);
//            response.setContentType("application/json; charset=utf-8");
//            PrintWriter writer = response.getWriter();
//            writer.print(responseConetnt);
//            writer.close();
//            response.flushBuffer();
//        }
        return flag;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {


    }

}
